package net.wesley.android.city;

import android.os.Handler;
import android.os.Message;

import net.wesley.android.City;
import net.yebaihe.sdk.HttpConnection;

public class TangShan extends City {

	private Handler request2handler=new Handler(){
		public void handleMessage(Message message){
			switch (message.what){
			case HttpConnection.DID_ERROR://DID ERROR
				callback.onComplete(-1, "");
				break;
			case HttpConnection.DID_SUCCEED://DID SUCC
				String body=(String)message.obj;
				int index=body.indexOf("违法行为</td>");
				String retvalue="";
				if (index>0){
					String str=body.substring(index+9).split("</table>")[0];
					String[] rows=str.split("<tr");
					for (int i=1;i<rows.length;i++){
						String[] cols=rows[i].split("<td");
						String shijian="未提供时间信息";
						String didian=cols[3].split("</td")[0].split(">")[1].trim();
						String code=cols[7].split("</td")[0].split(">")[1].trim();
						retvalue+=String.format("shijian:%s\ndidian:%s\ncode:%s\n\n",shijian,didian,code);
					}
					callback.onComplete(rows.length-1, retvalue);
				}
				else{
					callback.onComplete(-10001, "");
				}
				break;
			}
		}
	};

	public void requestParamsFinish(String[] values) {
		new HttpConnection(ctx,request2handler,"GBK").post("http://60.2.100.76:9080/wfxxcx/wfxxcxAction.htm?method=wzcx", 
				String.format("action=CheLiangWeiFa&operation=CheWeiFa&hpzl=02&fzjg=%%BC%%BD&hphm=%s",
						chepai.substring(1)));
	}

	@Override
	public boolean match(String chepai) {
		return chepai.startsWith("冀B");
	}

	@Override
	public String[] paramDesc() {
		return null;
	}

}
